package com.lyluly.coursemgmt.webmodule.foo;

import com.lyluly.coursemgmt.servicemodule.iService.IQuAnsService;
import com.lyluly.coursemgmt.servicemodule.model.QuAns;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @version v1.0
 * @author clc
 */
@Controller
@RequestMapping("/quAnses")
public class QuAnsController {
    @Autowired
    private IQuAnsService iQuAnsService;

    /**
     * 添加一条问答记录
     * @param quAns 问答记录实体类
     * @param response
     */
    @PostMapping
    public void addQuAns(@RequestBody QuAns quAns, HttpServletResponse response) {
        iQuAnsService.addQuAns(quAns);
    }

    /**
     * 根据记录ID修改一条问答记录
     * @param quAns 问答记录实体类
     * @param response
     */
    @PutMapping
    public void modifyQuAns(@RequestBody QuAns quAns, HttpServletResponse response) {
        iQuAnsService.modifyQuAns(quAns);
    }

    /**
     * 根据记录ID删除一条问答记录
     * @param quAnsId 问答记录ID
     * @param response
     */
    @DeleteMapping("/{quAnsId}")
    public void removeQuAns(@PathVariable int quAnsId, HttpServletResponse response) {
        iQuAnsService.removeQuAns(quAnsId);
    }

    /**
     * 根据记录ID查找一条问答记录
     * @param quAnsId 问答记录ID
     * @return 返回相应问答记录
     */
    @GetMapping("/quAnsId/{quAnsId}")
    @ResponseBody
    public QuAns findQuAnsById(@PathVariable int quAnsId) {
        return iQuAnsService.findQuAnsById(quAnsId);
    }

    /**
     * 查找所有问答记录
     * @return 返回所有问答记录
     */
    @GetMapping
    @ResponseBody
    public List<QuAns> findQuAnsList() {
        return iQuAnsService.findQuAnsList();
    }

    /**
     * 根据学生ID查找若干条问答记录
     * @param sId 学生ID
     * @return 返回相应问答记录
     */
    @GetMapping("/sId/{sId}")
    @ResponseBody
    public List<QuAns> findQuAnsListBySId(@PathVariable String sId) {
        return iQuAnsService.findQuAnsListBySId(sId);
    }

    /**
     * 根据教师ID查找若干条问答记录
     * @param tId 教师ID
     * @return 返回相应问答记录
     */
    @GetMapping("/tId/{tId}")
    @ResponseBody
    public List<QuAns> findQuAnsListByTId(@PathVariable String tId) {
        return iQuAnsService.findQuAnsListByTId(tId);
    }
}

